<template>
    <div class="table_box">
        <TableCard title="导游申请管理" :table_data="table_data" :search_box_visibale="false" :table_item="table_item"
            :user="'tour_guide_application'" :add_btn_visible="false" @SizeChange="SizeChange" @currentPage="currentPage"
            @is_add_dialog_visible="is_add_dialog_visible" @row_id="row_id" :total="total" @filter_second="filter_second"
            :loading="loading" />

    </div>
</template>

<script>
import TableCard from '@/components/reusable_components/table_card.vue'
export default {
    components: {
        TableCard,
    },

    data() {
        return {
            table_item: [
                // { key: 'index', value: '序号', default: '' },
                { key: 'user_name', value: '姓名', default: '' },
                { key: 'user_phone', value: '电话', default: '' },
                { key: 'information', width: '250', value: '导游证', default: '' },
                { key: 'agency_name', value: '意向旅行社', default: '' },
                // { key: 'if_succeed', value: '状态', default: '' },
            ],
            table_data: [],
            pageSize: 10,
            current_page: 1,
            add_dialog_visible: false,
            delete_row: 0,
            row_index: 0,
            total: 0,
            loading: true
        }
    },

    mounted() {
        this.SizeChange(this.pageSize);
        this.currentPage(this.current_page);
        this.get_applications()
    },

    methods: {

        // 根据子组件传来的信息，显示/关闭对话框
        is_add_dialog_visible(val) {
            this.add_dialog_visible = val
        },

        // async get_total_number() {
        //     try {
        //         const res = await this.$http.get("/findAllApplication");
        //         if (res.data.code === 2000) {
        //             this.total = res.data.data.length
        //         }
        //     } catch (error) {
        //         // console.log(error);
        //     }
        // },

        async get_applications() {
            this.loading = true
            try {
                const res = await this.$http.post('/findAllApplication', {
                    pageNum: this.current_page,
                    pageSize: this.pageSize
                });
                this.total = res.data.data.size
                this.table_data = res.data.data.information
                this.loading = false
            } catch (error) {
                // 这里对错误进行一些处理
            }
        },

        // 获取子组件传来的数据，当分页数据变化时，发送请求
        async SizeChange(size) {
            this.pageSize = size;
            this.get_applications()
        },

        async currentPage(page) {
            this.current_page = page;
            this.get_applications()
        },


        // 获取子组件传来的row_id
        row_id(val) {
            this.row_index = val
            this.add_form = this.table_data.find(item => item.id === val)
        },

        async filter_second(val) {
            let url = ''
            let if_ = 0
            switch (val) {
                case '不限':
                    url = '/findAllApplication'
                    this.pageSize = 10
                    this.current_page = 1
                    this.get_applications()
                    return
                case '待审批':
                    if_ = '0'
                    url = '/findAllWarningNeedCope'
                    break
                case '已通过':
                    url = '/selectApplicationByIf_succeed'
                    if_ = '1'
                    break
                case '未通过':
                    url = '/selectApplicationByIf_succeed'
                    if_ = '2'
                    break
                default:
                    break;
            }

            try {
                const res = await this.$http.post(url, {
                    if_succeed: if_ + '',
                    pageNum: this.current_page,
                    pageSize: this.pageSize
                });
                if (res.data.code === 2000) {
                    this.total = res.data.data.size
                    this.table_data = res.data.data.information
                    console.log(res)
                } else {
                    this.$message.error('出错啦')
                }
            } catch (error) {
                // console.log(error);
            }
        },

        async submit() {
            console.log('修改成功')
            try {
                const res = await this.$http.post("", {
                    // 携带数据
                });
                // 成功后关闭窗口
                this.add_dialog_visible = false
            } catch (error) {
                // console.log(error);
            }
        },
    },

}
</script>

<style lang="less" scoped>
.table_box {
    width: 100%;
    height: 100%;
}

.el-input {
    display: inline-block;
}
</style>